package org.mixare;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;

public class AugmentedCanvasView extends View {
		MixView app;

		public AugmentedCanvasView(Context context) {
			super(context);

			try {
				app = (MixView) context;

				app.killOnError();
			} catch (Exception ex) {
				app.doError(ex);
			}
		}

		@Override
		protected void onDraw(Canvas canvas) {
			try {
				if (app.fError) {
					Paint errPaint = new Paint();
					errPaint.setColor(Color.RED);
					errPaint.setTextSize(16);

					canvas.drawText("ERROR: ", 10, 20, errPaint);
					canvas.drawText("" + app.fErrorTxt, 10, 40, errPaint);

					return;
				}

				app.killOnError();

				MixView.dWindow.setWidth(canvas.getWidth());
				MixView.dWindow.setHeight(canvas.getHeight());
				MixView.dWindow.setCanvas(canvas);

				if (!MixView.view.isInited()) {
					MixView.view.init(MixView.dWindow.getWidth(),
							MixView.dWindow.getHeight());
				}

				MixView.view.draw(MixView.dWindow);
			} catch (Exception ex) {
				app.doError(ex);
			}
		}
	}
